package ru.pb.game.configs;

import java.io.IOException;

import org.apache.log4j.Logger;

import ru.pb.global.configs.Config;
import ru.pb.global.utils.ExitCode;

/**
 * @author Felixx
 */
public class GameServerConfig
{
	private static final Logger _log = Logger.getLogger(GameServerConfig.class);

	private static final String FileName = "./configs/gameserver.ini";

	public static boolean HARD_CLEANUP_ON_START_UP;

	public static int AUTH_SAVE_SERVER_VARIABLES;

	public static byte ID;
	public static String PASSWORD;
	public static int MAX_PLAYERS;
	public static boolean IS_GM_ONLY;
	public static int AGE_LIMIT;

	public static void load()
	{
		try
		{
			Config c = new Config(FileName);

			ID = c.getByteValue("gameserver", "id", (byte) 1);
			PASSWORD = c.getStringValue("gameserver", "password", "none");;
			MAX_PLAYERS = c.getIntegerValue("gameserver", "maxPlayers", 3000);
			IS_GM_ONLY = c.getBooleanValue("gameserver", "GMOnly", false);
			AGE_LIMIT = c.getIntegerValue("gameserver", "AgeLimit", 16);
			AUTH_SAVE_SERVER_VARIABLES = c.getIntegerValue("gameserver", "AutoSaveServerVariables", 300);
			HARD_CLEANUP_ON_START_UP = c.getBooleanValue("gameserver", "HardCleanupOnStartUp", false);
		}
		catch(IOException e)
		{
			_log.error("Не возможно загрузить файлы конфигурации.", e);
			System.exit(ExitCode.CODE_ERROR.getId());
		}
		catch(Exception e)
		{
			_log.error("Ошибка доступа к файлу или директории.", e);
			System.exit(ExitCode.CODE_ERROR.getId());
		}
		finally
		{
			_log.info(FileName + " Успешно загружен.");
		}
	}
}